/**
 * 
 */
package es.ats.codington.festival.services;

import java.io.IOException;
import java.sql.Connection;
import java.util.ArrayList;

import es.ats.codington.festival.daos.EventDAOImpl;
import es.ats.codington.festival.daos.PlaceDAOImpl;
import es.ats.codington.festival.domain.Place;

import es.ats.codington.festival.interfaces.services.iViewPlace;
import es.ats.codington.festival.utils.FERSDataConnection.FersDC;

/**
 * @author JAVA101_01
 *
 */
public class PlaceService implements iViewPlace {

	private Connection connection;
	
	@Override
	public Place viewPlace(int idplace) throws Exception {
		Place place2 = null;
		
		try{
			connection = FersDC.getConnection();
			if (connection == null) throw new IOException("It does not connect to DataBase");
			
			PlaceDAOImpl placedaoimpl=new PlaceDAOImpl(connection);
			 place2=placedaoimpl.viewPlace(idplace);
			
			}catch (Exception ex){
				System.out.println("Error Exception con mensaje: " + ex.getMessage());
				connection.rollback();
			}
			connection.close();
			return place2;
	}

	public ArrayList<Integer> getIdsPlace(String type) throws Exception {
		
		ArrayList<Integer> idsPlaceByType= new ArrayList<Integer>();
			try{
				connection = FersDC.getConnection();
				if (connection == null) throw new IOException("It does not connect to DataBase");
				
				PlaceDAOImpl placedaoimpl=new PlaceDAOImpl(connection);
				idsPlaceByType = placedaoimpl.getIdsPlace(type);
				
				}catch (Exception ex){
					System.out.println("Error Exception with message: " + ex.getMessage());
					connection.rollback();
				}
				connection.close();
				
			return idsPlaceByType;
			
		}
}
